#include "crc_calc.h"


unsigned short UpdateCrc(unsigned char ch, unsigned short *lpwCrc)
{
  ch = (ch^(unsigned char)((*lpwCrc) & 0x00FF));
  ch = (ch^(ch<<4));
  *lpwCrc = (*lpwCrc >> 8)^((unsigned short)ch << 8)^((unsigned short)ch<<3)^((unsigned short)ch>>4);
  return(*lpwCrc);
}


void ComputeCrc(u8_t *Data, u16_t Length,u8_t *TransmitFirst, u8_t *TransmitSecond)
{
  unsigned char chBlock;
  unsigned short wCrc;
 // switch(CRCType) 
  //{
 //   case CRC_A:
  //    wCrc = 0x6363; /* ITU-V.41 */
  //    break;
  //  case CRC_B:
      wCrc = 0xFFFF; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
   //   break;
   // default:
  //  return;
  //}
  
  do 
  {
    chBlock = *Data++;
    UpdateCrc(chBlock, &wCrc);
   } while (--Length);

    //if (CRCType == CRC_B)
    wCrc = ~wCrc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
    *TransmitFirst = (unsigned char) (wCrc & 0xFF);
    *TransmitSecond = (unsigned char) ((wCrc >> 8) & 0xFF);
    
return;
}



